package com.mycompany.interceptor;

import java.util.Date;
import java.util.logging.Logger;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

public class LoggingInterceptor {

    //private Logger logger = Logger.getLogger("com.mycompany.pomodoro");

    @AroundInvoke
    public Object logMethod(InvocationContext ic) throws Exception {

        Date before = new Date();
        
        //logger.entering(ic.getTarget().toString(), ic.getMethod().getName());
        System.out.println("getTarget" + ic.getTarget().toString() + ";  getMethod" + ic.getMethod().getName());
        try {
            return ic.proceed();
        } finally {
            //logger.exiting(ic.getTarget().toString(), ic.getMethod().getName());
            
            Date after = new Date();
            
            System.out.println("getTarget" + ic.getTarget().toString() + ";  getMethod" + ic.getMethod().getName());
            
            System.out.println("Elapsed time: " + (after.getTime() - before.getTime()) + " milliseconds");
        }
    }
}
